<?php
/*====================================*\
|| ################################## ||
|| # XtreMedia                   	# ||
|| # ------------------------------	# ||
|| # Coded by REDPHOENIX89			# ||
|| # Y!m : RedPhoenix89				# ||
|| ################################## ||
\*====================================*/
define('IN_MEDIA',true);
require_once 'includes/debug.php';
// TIME LOAD
$m_time = explode(" ",microtime()); 
$m_time = $m_time[0] + $m_time[1]; 
$starttime = $m_time;

include('includes/config.php');
include('includes/functions.php');
include('includes/class_template.php');
include("web_title.php");
//debug($_POST);

$isLoggedIn = m_checkLogin();

include("ajax.php");


$value = array();

if ($_GET['archive']) {
     include('archive.php');
   exit();
}

	// ONLINE
/*	if (!$isLoggedIn) {
		$num = $mysql->num_rows($mysql->query("SELECT sid FROM ".$tb_prefix."online WHERE sid = '".SID."'"));
		if ($num == 0) $mysql->query("INSERT INTO ".$tb_prefix."online (timestamp, sid, ip) VALUES ('".NOW."', '".SID."', '".IP."')");
		else $mysql->query("UPDATE ".$tb_prefix."online SET timestamp='".NOW."',ip='".IP."' WHERE sid='".SID."'");
	}
*/
	// TEMPLATES
	if($template) {
		$default_tpl = m_get_config("default_tpl");
		$sql_temp = $mysql->query("SELECT * FROM ".$tb_prefix."tpl WHERE tpl_fname = '$template'");
		if($mysql->num_rows($sql_temp)) {
			$_SESSION['current_tpl'] =  $template;
			create_cookie("TPL",$template); 
			echo "<script language='JavaScript'>{ window.parent.location='".$_SESSION['current_url']."' }</script>";
		}
	}
	else {
			$_SESSION['current_tpl'] = m_get_config("default_tpl");
	}
	if(get_cookie("TPL")) {
			$_SESSION['current_tpl'] = get_cookie("TPL");
	}
	$month = date('m',NOW);
	$current_month = m_get_config('current_month');
	if ($month != $current_month) {
		$mysql->query("UPDATE ".$tb_prefix."data SET m_viewed_month = 0, m_downloaded_month = 0");
		$mysql->query("UPDATE ".$tb_prefix."config SET config_value = ".$month." WHERE config_name = 'current_month'");
	}
/*	$week = date('w',NOW);
	$current_week = m_get_config('current_week');
	if ($week != $current_week) {
		$mysql->query("UPDATE ".$tb_prefix."data SET m_viewed_week = 0");
		$mysql->query("UPDATE ".$tb_prefix."data SET m_rating_week = 0, m_rating_total_week = 0");
		$mysql->query("UPDATE ".$tb_prefix."data SET m_downloaded_week = 0");		
		$mysql->query("UPDATE ".$tb_prefix."config SET config_value = ".$week." WHERE config_name = 'current_week'");
	}
	$day = date('d',NOW);
	$current_day = m_get_config('current_day');
	if ($day != $current_day) {
		$mysql->query("UPDATE ".$tb_prefix."data SET m_viewed_day = 0");
		$mysql->query("UPDATE ".$tb_prefix."config SET config_value = ".$day." WHERE config_name = 'current_day'");
	}	
	*/
// TIME LOAD 
$round = 3;
$m_time = explode(" ",microtime()); 
$m_time = $m_time[0] + $m_time[1]; 
$endtime = $m_time; 
$totaltime = ($endtime - $starttime); 
// TEMP
$tpl_link = $mainURL."/templates/".$_SESSION['current_tpl']."";
$web_name = m_get_config("web_title");
include("templates/".$_SESSION['current_tpl']."/main.html");
$_SESSION['current_url'] = CURRENT_LINK;

?>